package jdk8;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import org.eclipse.collections.impl.utility.Iterate;
import org.junit.Test;

import java.util.Arrays;
import java.util.UUID;

/**
 * @author zhoujie
 * @date 2020-10-26
 */
public class eclipseCollections {
    @Test
    public  void test01(){
        Iterate.forEachWithIndex(Arrays.asList("1", "2", "3","8"), (item, i)->{
            System.out.println("item:"+item+" i:"+i);
        });
    }

    @Test
    public  void test02(){
        UUID.randomUUID();
        forEach(Arrays.asList("1", "2", "3","8"), (item, i)->{
            System.out.println("item:"+item+" i:"+i);
        });
    }

    /**
     * 循环遍历 {@link Iterable}，使用{@link CollUtil.Consumer} 接受遍历的每条数据，并针对每条数据做处理
     *
     * @param <T>      集合元素类型
     * @param iterable {@link Iterable}
     * @param consumer {@link CollUtil.Consumer} 遍历的每条数据处理器
     */
    public static <T> void forEach(Iterable<T> iterable, CollUtil.Consumer<T> consumer) {
        CollUtil.forEach(iterable.iterator(),consumer);
    }

}
